package com.wuyb.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wuyb.mapper.MenuMapper;
import com.wuyb.pojo.Menu;
import com.wuyb.pojo.User;
import com.wuyb.pojo.entity.BaseResponse;
import com.wuyb.pojo.entity.ResultUtils;
import com.wuyb.service.MenuService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: wyb
 * @Date: 2024/01/02/18:57
 * @Description:
 */
@Service
@Slf4j
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements MenuService {

    @Resource
    private MenuMapper menuMapper;

    @Override
    public BaseResponse<?> getMenuByUserId() {
        List<Menu> menus = menuMapper.getMenusByUserId(
                (
                        (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()
                ).getId()
        );
        return ResultUtils.success(menus);
    }
}
